//
//  JourneyMenuViewController.m
//  MyTravel
//
//  Created by Hunk on 11-5-25.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "JourneyMenuViewController.h"
#import "JourneyInfoViewCotroller.h"
#import "JourneyIntroductionViewController.h"
#import "JourneyDetailsViewController.h"
#import "JourneyContactInfoViewController.h"
#import "JourneyNoticeViewController.h"

@implementation JourneyMenuViewController
@synthesize titleForHeader, journeyId, isMyFavorite;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

    [self setTitle:@"主菜单"];
    
    // Init tableView
	UITableView* tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420) 
                                                          style:UITableViewStyleGrouped];
	tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [tableView setDelegate:self];
    [tableView setDataSource:self];
	[self.view addSubview:tableView];
    [tableView release];
}

#pragma mark -
#pragma mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{	
	return 60.0;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
	return titleForHeader;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier:CellIdentifier] autorelease];
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    switch (indexPath.row)
    {
        case 0: 
        {
            UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 50, 50)];
            [imageView setBackgroundColor:[UIColor clearColor]];
            [imageView setImage:[UIImage imageNamed:@"xingchengcankao.png"]];
            [cell.contentView addSubview:imageView];
            [imageView release];
            
            UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 150, 50)];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont systemFontOfSize:20]];
            [label setTextAlignment:UITextAlignmentCenter];
            [label setText:@"行程参考"];
            [cell.contentView addSubview:label];
            [label release];
        }
            break;
        case 1: 
        {
            UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 50, 50)];
            [imageView setBackgroundColor:[UIColor clearColor]];
            [imageView setImage:[UIImage imageNamed:@"xingchengjianjie.png"]];
            [cell.contentView addSubview:imageView];
            [imageView release];
            
            UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 150, 50)];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont systemFontOfSize:20]];
            [label setTextAlignment:UITextAlignmentCenter];
            [label setText:@"行程简介"];
            [cell.contentView addSubview:label];
            [label release];
        }
            break;
        case 2:
        {
            UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 50, 50)];
            [imageView setBackgroundColor:[UIColor clearColor]];
            [imageView setImage:[UIImage imageNamed:@"cantuanxuanze.png"]];
            [cell.contentView addSubview:imageView];
            [imageView release];
            
            UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 150, 50)];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont systemFontOfSize:20]];
            [label setTextAlignment:UITextAlignmentCenter];
            [label setText:@"参团选择"];
            [cell.contentView addSubview:label];
            [label release];
        }
            break;
        case 3: 
        {
            UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 50, 50)];
            [imageView setBackgroundColor:[UIColor clearColor]];
            [imageView setImage:[UIImage imageNamed:@"lianxifangshi.png"]];
            [cell.contentView addSubview:imageView];
            [imageView release];
            
            UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 150, 50)];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont systemFontOfSize:20]];
            [label setTextAlignment:UITextAlignmentCenter];
            [label setText:@"联系方式"];
            [cell.contentView addSubview:label];
            [label release];
        }
            break;
        case 4: 
        {
            UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 5, 50, 50)];
            [imageView setBackgroundColor:[UIColor clearColor]];
            [imageView setImage:[UIImage imageNamed:@"cantuanxuzhi.png"]];
            [cell.contentView addSubview:imageView];
            [imageView release];
            
            UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 150, 50)];
            [label setBackgroundColor:[UIColor clearColor]];
            [label setFont:[UIFont systemFontOfSize:20]];
            [label setTextAlignment:UITextAlignmentCenter];
            [label setText:@"参团须知"];
            [cell.contentView addSubview:label];
            [label release];
        }
            break;
        default:break;
    }
    return cell;
}

#pragma mark -
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
    
 //   NSLog(@"%@\n", journeyId);
    
    switch (indexPath.row)
    {
        case 0:
        {
            JourneyDetailsViewController* journeyDetailsViewController = [JourneyDetailsViewController alloc];
            journeyDetailsViewController.journeyId = journeyId;
            journeyDetailsViewController.journeyName = titleForHeader;
            [self.navigationController pushViewController:journeyDetailsViewController animated:YES];
            [journeyDetailsViewController release];
        }
            break;
        case 1:
        {
            JourneyIntroductionViewController* journeyIntroductionViewController = [JourneyIntroductionViewController alloc];
            journeyIntroductionViewController.journeyId = journeyId;
            [self.navigationController pushViewController:journeyIntroductionViewController animated:YES];
            [journeyIntroductionViewController release];
        }
            break;
        case 2:
        {
            JourneyInfoViewCotroller* journeyInfoViewCotroller = [JourneyInfoViewCotroller alloc];
            journeyInfoViewCotroller.journeyId = journeyId;
            [self.navigationController pushViewController:journeyInfoViewCotroller animated:YES];
            [journeyInfoViewCotroller release];
        }
            break;
        case 3:
        {
            JourneyContactInfoViewController* journeyContactInfoViewController = [JourneyContactInfoViewController alloc];
            journeyContactInfoViewController.journeyTitle = titleForHeader;
            journeyContactInfoViewController.journeyId = journeyId;
            [self.navigationController pushViewController:journeyContactInfoViewController animated:YES];
            [journeyContactInfoViewController release];
        }
            break;
        case 4:
        {
            JourneyNoticeViewController* journeyNoticeViewController = [JourneyNoticeViewController alloc];
            journeyNoticeViewController.journeyId = journeyId;
            [self.navigationController pushViewController:journeyNoticeViewController animated:YES];
            [journeyNoticeViewController release];
        }
            break;
        default:
            break;
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
